/*
 * FrameGui.java
 *
 * Copyright (C) 2013 UPOU.
 * IS214 - Programming Languages
 * All Rights Reserved.
 *
 * @author Mary Joy Pascual and Simon Zagado
 */

package com.upittc.flopol.gui;

import java.util.List;

import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;

import com.upittc.flopol.constant.FlopolConstant;
import com.upittc.flopol.gui.beans.MenuBean;
import com.upittc.flopol.gui.beans.SubMenuBean;
import com.upittic.flopol.action.MenuAction;

public class FrameGui extends JFrame {

	private static final long serialVersionUID = -8162005689354165573L;

	private FramePanel consolePanel;

	public FrameGui() {
		initFrame();
		initPanels();
		initMenu();
	}

	private void initPanels() {
		consolePanel = new FramePanel();
		setContentPane(consolePanel);
	}

	private final void initFrame() {
		setTitle(FlopolConstant.FLOPOL);
		setSize(1000, 650);
		setLocationRelativeTo(null);
		setResizable(false);
		setDefaultCloseOperation(EXIT_ON_CLOSE);
	}

	private final void initMenu() {

		MenuAction menuData = new MenuAction();
		List<MenuBean> menuDataList = menuData.generateMenuList(consolePanel);

		JMenuBar menubar = new JMenuBar();

		for (MenuBean menuBean : menuDataList) {

			JMenu menu = new JMenu(menuBean.getMenuName());
			menu.setMnemonic(menuBean.getKeyEvent());

			for (SubMenuBean submenu : menuBean.getSubMenuList()) {
				JMenuItem menuItem = new JMenuItem(submenu.getSubMenuName(),
						submenu.getImageIcon());
				menuItem.setMnemonic(submenu.getSubEvent());
				menuItem.setToolTipText(submenu.getTooltip());
				menuItem.addActionListener(submenu.getAction());
				menu.add(menuItem);
			}

			menubar.add(menu);
		}
		setJMenuBar(menubar);

	}
}
